<template>
  <div>
    <el-dialog
      :title="liulanchildren.trialTypeName"
      :visible.sync="dialogVisible"
      width="60%"
      center>
      <div>
        <div class="shangxia" >
          <el-form :model=zibaogaoform label-position="right" label-width="100">
              <div v-for="(item,index) in formlist" :key="index" class="twobox" >
                <div v-if="item.text!=='试验环境'" class="texth">{{ item.text=='台账信息'?'基本信息':item.text=='试验数据'?'变压器试验数据':item.text }}</div>
                <div v-for="(itemtwo,indextwo) in item.children" :key="indextwo" class="threebox">
                <div v-if="itemtwo.text!=='试验环境'"><span class="bluebgc"></span> <span class="bluetext">{{ itemtwo.text }}</span></div>
                <div  class="clearfix" style="padding: 10px;">
                  <el-col :span="8" v-for="(itemthree,indexthree) in itemtwo.children" :key="indexthree" >
                    <el-form-item style="font-size: 20px;" :label="itemthree.trialProjectName" v-if="itemtwo.text!=='绝缘电阻'&&itemtwo.text!=='交流耐压'&&itemtwo.text!=='直流电阻'&&itemtwo.text!=='变比实验'&&itemthree.trialProjectName!=='温度'&&itemthree.trialProjectName!=='湿度'">
                      <el-input v-if="itemthree.dataType!=='2'&&itemthree.dataType!=='3'&&itemthree.dataType!=='4'" v-model="itemthree.value" :placeholder="`请输入${itemthree.trialProjectName}`" style="width: 100%;" size="small">
                        <span slot="suffix">{{ itemthree.unit }}</span>
                      </el-input>
                      <el-input v-else v-model="itemthree.convertValue" :placeholder="`请输入${itemthree.trialProjectName}`" style="width: 100%;" size="small">
                        <span slot="suffix">{{ itemthree.unit }}</span>
                      </el-input>
                    </el-form-item>
                    <el-form-item label="测试仪表名称" v-if="itemthree.trialProjectName=='测试仪表名称'">
                        <el-input  v-model="itemthree.value"  style="width: 100%;" size="small">
                        </el-input>
                    </el-form-item>
                    <el-form-item label="测试仪表型号" v-if="itemthree.trialProjectName=='测试仪表型号'">
                        <el-input  v-model="itemthree.value"  style="width: 100%;" size="small">
                        </el-input>
                    </el-form-item>
                    <el-form-item label="直流电阻测试仪表名称" v-if="itemthree.trialProjectName=='直流电阻测试仪表名称'">
                        <el-input  v-model="itemthree.value"  style="width: 100%;" size="small">
                        </el-input>
                    </el-form-item>
                    <el-form-item label="直流电阻测试仪表型号" v-if="itemthree.trialProjectName=='直流电阻测试仪表型号'">
                        <el-input  v-model="itemthree.value"  style="width: 100%;" size="small">
                        </el-input>
                    </el-form-item>
                    <el-form-item label="变比测试仪表名称" v-if="itemthree.trialProjectName=='变比测试仪表名称'">
                        <el-input  v-model="itemthree.value"  style="width: 100%;" size="small">
                        </el-input>
                    </el-form-item>
                    <el-form-item label="变比测试仪表型号" v-if="itemthree.trialProjectName=='变比测试仪表型号'">
                        <el-input  v-model="itemthree.value"  style="width: 100%;" size="small">
                        </el-input>
                    </el-form-item>
                  </el-col>
                  <div v-if="itemtwo.text=='绝缘电阻'" v-html="getjueyuandianzu(itemtwo.children)"></div>
                  <div v-if="itemtwo.text=='交流耐压'" v-html="getjiaoliunaiya(itemtwo.children)" ></div>
                  <div v-if="itemtwo.text=='直流电阻'" v-html="getzhiliudianzu(itemtwo.children)" ></div>
                  <div v-if="itemtwo.text=='变比实验'" v-html="getbianbishiyan(itemtwo.children)" ></div>
                </div>
                </div>
                <!-- <div v-if="item.text=='实验环境'"></div> -->
             </div>
             <div class="foorterxunhuan">
                  <el-col :span="12" v-for="(item,index) in forterlist" :key="index">
                    <el-form-item :label="item.trialProjectName">
                      <el-input v-if="item.dataType!=='2'&&item.dataType!=='3'&&item.dataType!=='4'" v-model="item.value" style="width: 100%;" :placeholder="`请输入${item.trialProjectName}`"  size="small"></el-input>
                      <el-input v-else v-model="item.convertValue" style="width: 100%;" :placeholder="`请输入${item.trialProjectName}`"  size="small"></el-input>
                    </el-form-item>
                  </el-col>
                </div>
          </el-form>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false" size="small">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { getchushihuazibaogaoapi } from '@/api/Experimental-report/Main-information'
import {setlistsort} from '@/utils/array'
export default {
  name: 'CallPoliceChildrenRowse',
  props: {
    liulanchildren: {
      type:Object
    },
    orgNo: {
      type:String
    }
  },
  data() {
    return {
      zibaogaoform:{},
      formlist:[],
      dialogVisible: false,
      forterlist:[]
    };
  },

  mounted() {

  },

  methods: {
    getbianbishiyan(data) {
      return `
        <div style="width: 100%;border:1px solid #ccc;display:flex;">
           <div style="width: 100%;">
              <div style="width: 100%;height:50px;display:flex;background-color: #f1f1f1;">
                <div style="width:16.66%;text-align: center;border-right:1px solid #ccc;height:50px;line-height: 50px;">相别</div>
                <div style="width:16.66%;text-align: center;border-right:1px solid #ccc;height:50px;line-height: 50px;">I</div>
                <div style="width:16.66%;text-align: center;border-right:1px solid #ccc;height:50px;line-height: 50px;">II</div>
                <div style="width:16.66%;text-align: center;border-right:1px solid #ccc;height:50px;line-height: 50px;">III</div>
                <div style="width:16.66%;text-align: center;border-right:1px solid #ccc;height:50px;line-height: 50px;">IV</div>
                <div style="width:16.66%;text-align: center;height:50px;line-height: 50px;">V</div>
              </div>
              <div style="display:flex;">
                 <div style="background-color: #f1f1f1;width:16.66%;">
                   <div style="text-align: center;height:50px;line-height: 50px;border-top:1px solid #ccc;">AB(ao)%</div>
                   <div style="text-align: center;height:50px;line-height: 50px;border-top:1px solid #ccc;">BC(bo)%</div>
                   <div style="text-align: center;height:50px;line-height: 50px;border-top:1px solid #ccc;">CA(co)%</div>
                 </div>
                 <div style="flex:1;display:flex;flex-wrap: wrap;">${this.genbianbiHtml(data)}</div>
              </div>
           </div>
        </div>
      `
    },
    genbianbiHtml(data) {
      let arr=['AB(ao)_I','AB(ao)_II','AB(ao)_III','AB(ao)_IV','AB(ao)_V','BC(bo)_I','BC(bo)_II','BC(bo)_III','BC(bo)_IV','BC(bo)_V','CA(co)_I','CA(co)_II','CA(co)_III','CA(co)_IV','CA(co)_V']
      let list = data.filter(ele => ele.trialProjectName !== '变比测试仪表名称' && ele.trialProjectName !== '变比测试仪表型号')
      let listarr = setlistsort(list, arr)
      let itemsHtml = '';
      listarr.forEach((item, index) => {
        itemsHtml += `<div style="width: 20%;height:50px;text-align: center;line-height: 50px;
        border-left: 1px solid #ccc;border-top:1px solid #ccc;">${item.value?item.value:''}</div>`;
      });
      return itemsHtml;
    },
    getzhiliudianzu(data) {
      return `
      <div style="width: 100%;display: flex;border:1px solid #ccc;border-bottom:none;box-sizing: border-box;">
        <div style="width:100%;">
          <div style="display:flex;background-color: #f1f1f1;">
            <div style="width: 16.66%;height:50px;text-align: center;line-height: 50px;border-bottom: 1px solid #ccc;border-right:1px solid #ccc;">被试绕组</div>
            <div style="width: 16.66%;height:50px;text-align: center;line-height: 50px;border-bottom: 1px solid #ccc;border-right:1px solid #ccc;">分接头位置</div>
            <div style="width: 16.66%;height:50px;text-align: center;line-height: 50px;border-bottom: 1px solid #ccc;border-right:1px solid #ccc;">AB(ao)</div>
            <div style="width: 16.66%;height:50px;text-align: center;line-height: 50px;border-bottom: 1px solid #ccc;border-right:1px solid #ccc;">BC(bo)</div>
            <div style="width: 16.66%;height:50px;text-align: center;line-height: 50px;border-bottom: 1px solid #ccc;border-right:1px solid #ccc;">CA(co)</div>
            <div style="width: 16.66%;height:50px;text-align: center;line-height: 50px;border-bottom: 1px solid #ccc;">误差(%)</div>
          </div>
          <div style="display:flex;">
            <div style="width:33.33%;background-color: #f1f1f1;">
            <div style="display:flex;">
              <div style="height:250px;line-height: 250px;text-align: center;width:50%;border-bottom:1px solid #ccc;">高压(Ω)</div>
              <div style="width:50%;border-left:1px solid #ccc;">
                 <div style="height:50px;line-height: 50px;text-align: center;border-bottom:1px solid #ccc;">I</div>
                 <div style="height:50px;line-height: 50px;text-align: center;border-bottom:1px solid #ccc;">II</div>
                 <div style="height:50px;line-height: 50px;text-align: center;border-bottom:1px solid #ccc;">III</div>
                 <div style="height:50px;line-height: 50px;text-align: center;border-bottom:1px solid #ccc;">IV</div>
                 <div style="height:50px;line-height: 50px;text-align: center;border-bottom:1px solid #ccc;">V</div>
              </div>
            </div>
            <div style="height:50px;line-height: 50px;text-align: center;border-bottom:1px solid #ccc;">低压(Ω)</div>
          </div>
          <div style="flex:1;display:flex;flex-wrap: wrap;">${this.genzhiliuHtml(data)}</div>
          </div>
        </div>
       </div>
        `
    },
    genzhiliuHtml(data) {
      let list =data.filter(ele=>ele.trialProjectName!=='直流电阻测试仪表名称'&&ele.trialProjectName!=='直流电阻测试仪表型号')
      let itemsHtml = '';
      list.forEach((item, index) => {
        itemsHtml += `<div style="width: 25%;height:50px;text-align: center;line-height: 50px;
        border-left: 1px solid #ccc;border-bottom:1px solid #ccc;">${item.value?item.value:''}</div>`;
      });
      return itemsHtml;
    },
    getjiaoliunaiya(data) {
      // &&itemthree.trialProjectName!=='高压侧对低压及地'&&itemthree.trialProjectName!=='低压侧对高压及地'&&itemthree.trialProjectName!=='高压侧对低压及地时间'&&itemthree.trialProjectName!=='低压侧对高压及地时间'
      return `
        <div style="width: 100%;display: flex;border:1px solid #ccc;border-bottom:none;">
          <div style="width: 20%;">
            <div style="height:50px;background-color: #f1f1f1;text-align: center;line-height: 50px;border-bottom:1px solid #ccc;">高压侧对低压及地</div>
            <div style="height:50px;background-color: #f1f1f1;text-align: center;line-height: 50px;border-bottom:1px solid #ccc;">低压侧对高压及地</div>
          </div>
          <div style="flex:1;">
            ${this.genjiaoliuHtml(data)}
           </div>
        </div>
      `
    },
    genjiaoliuHtml(data) {
      let list =data.filter(ele=>ele.trialProjectName!=='测试仪表名称'&&ele.trialProjectName!=='测试仪表型号')
      let itemsHtml = '';
      list.forEach((item, index) => {
        itemsHtml += `<div style="width: 50%;height:50px;display: inline-block;text-align: center;line-height: 50px;
        border: 1px solid #ccc;border-top:none;position: relative;">${item.value?item.value:''}
        <span style="position: absolute;right:10px">${item.unit}</span></div>`;
      });
      return itemsHtml;
    },
    getjueyuandianzu(data) {
      var sortOrder = ['高压R15', '低压R15', '铁芯R15', '高压R60', '低压R60', '铁芯R60', '高压吸收比', '低压吸收比', '铁芯吸收比']
      let list = setlistsort(data, sortOrder)
      // 创建一个新的对象，用于按照需要的结构组织数据
      return `
       <div  style="width: 100%;border:1px solid #ccc;border-bottom:none;">
         <div  style="display: flex;">
          <div style="width: 25%;height:50px;background-color: #f1f1f1;text-align: center;line-height: 50px;border-bottom: 1px solid #ccc;">被试绕组</div>
          <div style="width: 25%;height:50px;background-color: #f1f1f1;text-align: center;line-height: 50px;border-bottom: 1px solid #ccc;">高压</div>
          <div style="width: 25%;height:50px;background-color: #f1f1f1;text-align: center;line-height: 50px;border-bottom: 1px solid #ccc;">低压</div>
          <div style="width: 25%;height:50px;background-color: #f1f1f1;text-align: center;line-height: 50px;border-bottom: 1px solid #ccc;">铁芯</div>
         </div>
         <div style="display: flex;">
           <div style="width: 25%;">
            <div style="height:50px;background-color: #f1f1f1;text-align: center;line-height: 50px;border-bottom: 1px solid #ccc;">R15</div>
            <div style="height:50px;background-color: #f1f1f1;text-align: center;line-height: 50px;border-bottom: 1px solid #ccc;">R60</div>
            <div style="height:50px;background-color: #f1f1f1;text-align: center;line-height: 50px;border-bottom: 1px solid #ccc;">吸收比</div>
           </div>
           <div style="flex:1;">
            ${this.generateItemsHtml(list)}
           </div>
         </div>
       </div>
      `
    },
    generateItemsHtml(data) {
      let itemsHtml = '';
      data.forEach((item, index) => {
        itemsHtml += `<div style="width: 33.33%;height:50px;display: inline-block;text-align: center;line-height: 50px;
        border-bottom: 1px solid #ccc;">${item.value?item.value:''}</div>`;
      });
      return itemsHtml;
    }
  },
  watch: {
    async dialogVisible(val) {
      if (val) {
        const loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        target: document.querySelector('.shangxia')
      });
        const { data: { list } } = await getchushihuazibaogaoapi({ id: this.liulanchildren.id, orgNo: this.orgNo, trialType: this.liulanchildren.trialType })
        this.formlist = list.slice(0, list.length - 2)
        let arr1=[]
        for (let i = 0; i < list.length; i++){
          for (let j = 0; j < list[i].children.length; j++){
            for (let k = 0; k < list[i].children[j].children.length; k++) { 
               arr1.push(list[i].children[j].children[k])
            }
          }
        }
        let arr3 = ['结论', '备注', '试验员', '审核人', '批准人']
        const arr4 = arr1.filter(ele => { 
          for (let i = 0; i < arr3.length; i++){
             if(ele.trialProjectName==arr3[i]){
              return ele
             }
          }
        })
        this.forterlist = arr4
        loading.close();
      }
    }
  }
};
</script>

<style scoped>
    .shangxia{
      height: 500px;
      overflow: auto;
      border-bottom: 1px solid #ccc;
      .foorterxunhuan{
              margin-top: 30px;
              width: 100%;
              display: flex;
              flex-wrap: wrap;
               ::v-deep .el-form-item__label{
                font-size: 18px;
                  color: #323232;
                  font-weight: bold;
               }
              .inputbox{
                margin-bottom: 20px;
                width: 40%;
                .text{
                  font-size: 18px;
                  color: #323232;
                  font-weight: bold;
                }
              }
            }
      .twobox{
        padding: 15px 0;
        .texth{
              font-size: 18px;
              font-weight: bold;
              color: #323232;
            }
        .threebox{
          padding: 10px;
            .bluebgc{
              display: inline-block;
              width: 5px;
              height: 16px;
              background-color: #187cf5;
              margin-right: 10px;
              border-radius: 3px;
              vertical-align: middle;
            }
            .bluetext{
              display: inline-block;
              vertical-align: middle;
              font-size: 18px;
              color: #323232;
            }
        }
      }
    }
.clearfix::after {
  content: "";
  clear: both;
  display: table;
  .bigwaiwei{
    width: 100%;
    .bgc{
      background-color: #f1f1f1;
    }
    .header{
      display: flex;
      .widthfour{
        width: 25%;
        height: 50px;
        text-align: center;
        line-height: 50px;
      }
    }
    .footer{
      display: flex;
      .footleft{
        width: 25%;
      }
    }
  }
}
::v-deep .el-form-item{
  display: flex;
  margin-right: 10px;
}
::v-deep .el-form-item__content{
  flex:1;
}
</style>